package com.xiaolin.spring.xml;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @ClassName LifeCycleTest
 * @Description TODO
 * @Detail 生命周期方法
 * @Author MyPC
 * @Date 2020/10/27
 * @Version 1.0
 */
public class LifeCycleTest {
    //容器创建或bean对象初始化时调用
//    @PostConstruct
    public void init(){
        System.out.println("我被初始化了。。。");
    }

    //容器销毁或bean对象销毁时时调用
//    @PreDestroy
    public void destroy(){
        System.out.println("我被销毁了");
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext=new ClassPathXmlApplicationContext("life-cycle.xml");
        LifeCycleTest init = applicationContext.getBean("init", LifeCycleTest.class);
        System.out.println(init);
        //销毁容器
        applicationContext.registerShutdownHook();
    }
}
